home *** CD-ROM | disk | FTP | other *** search
/ Total Web Page (Professional Suite) / Total Web Page 99.iso / tinyScroller.java < prev    next >
Text File  |  1998-10-30  |  6KB  |  197 lines

  1. import java.applet.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5. public class tinyScroller extends Applet
  6.     implements Runnable {                // Threaded application
  7.  
  8.     int maxLines=100,                    // Added by a user
  9.     direction=0,                         // 0=up, 1=down
  10.     delay=100,                           // delay, controls scroll speed
  11.     spacing=12,                          // spacing, between lines
  12.     XPos=5,                              // XPos, indent 
  13.     maxLine=0,                           // maxLine, # of Lines being sent 
  14.     current,                             // current, initial position 
  15.     height;                              // height, of the applet
  16.  
  17.     String[] Line = new String[maxLines];// Lines, to be displayed, 12 max
  18.  
  19.     Image offImage, bg;                  // Double buffering to eliminate
  20.     Graphics offGrfx;                    // frame flicker
  21.  
  22.     Font outFont;                        // Output font (if passed)
  23.     boolean customFont = false;          // Flag, is there a custom outFont?
  24.                                     
  25.     Color background, fontColor;
  26.  
  27.     Thread runner;
  28.  
  29.     public void init() {
  30.  
  31.         /****  Get attributes, if available  ****/
  32.         String bgRed$      = getParameter("BGRED");
  33.         String bgGreen$    = getParameter("BGGREEN");
  34.         String bgBlue$     = getParameter("BGBLUE");
  35.         String fgRed$      = getParameter("FGRED");
  36.         String fgGreen$    = getParameter("FGGREEN");
  37.         String fgBlue$     = getParameter("FGBLUE");
  38.         String spacing$    = getParameter("SPACING");
  39.         String delay$      = getParameter("DELAY");
  40.         String XPos$       = getParameter("XPOS");
  41.         String maxLine$    = getParameter("MAXLINE");
  42.         String background$ = getParameter("BACKGROUND");
  43.         String fontName$   = getParameter("FONTNAME");
  44.         String fontSize$   = getParameter("FONTSIZE");
  45.         String direction$  = getParameter("DIRECTION");
  46.  
  47.         /****           Data lines           ****/
  48.         for (int x=0; x<maxLines; x++) {
  49.             Line[x] = getParameter("LINE" + Integer.toString(x+1));
  50.         }
  51.  
  52.         /****          Setting Font          ****/
  53.         if ((fontSize$ != null) && (fontName$ != null)) {
  54.             int size = Integer.parseInt(fontSize$);
  55.             outFont = new Font(fontName$, Font.PLAIN, size);
  56.             customFont = true;
  57.         }
  58.  
  59.         /****          Find maxline         ****/
  60.         for (int x=0; x<maxLines; x++) {
  61.             if (Line[x] == null) break;
  62.             maxLine++;
  63.         }
  64.         
  65.         /****      Convert color values     ****/
  66.         int Red=255;
  67.         if (bgRed$ != null)
  68.       Red = Integer.parseInt(bgRed$);
  69.  
  70.         int Green=255; 
  71.         if (bgGreen$ != null)
  72.       Green = Integer.parseInt(bgGreen$);
  73.  
  74.         int Blue=255;
  75.         if (bgBlue$ != null)
  76.       Blue = Integer.parseInt(bgBlue$);
  77.  
  78.         int fRed=0;
  79.         if (fgRed$ != null)
  80.           fRed = Integer.parseInt(fgRed$);
  81.  
  82.         int fGreen=0; 
  83.         if (fgGreen$ != null)
  84.           fGreen = Integer.parseInt(fgGreen$);
  85.  
  86.         int fBlue=0;
  87.         if (fgBlue$ != null)
  88.           fBlue = Integer.parseInt(fgBlue$);
  89.  
  90.         /****   Convert attribute values   ****/
  91.         if (spacing$ != null)
  92.       spacing = Integer.parseInt(spacing$);
  93.         
  94.         if (delay$ != null)
  95.       delay = Integer.parseInt(delay$);
  96.        
  97.         if (XPos$ != null)
  98.       XPos = Integer.parseInt(XPos$);
  99.        
  100.         height = size().height;                                              
  101.  
  102.         if (direction$ != null)
  103.           direction = Integer.parseInt(direction$);
  104.  
  105.         if (background$ !=null)
  106.           bg = getImage(getDocumentBase(), background$);
  107.  
  108.         /****        Set init index       ****/
  109.         if (direction == 0) { 
  110.           current = height;
  111.         }
  112.         else {
  113.           current = -(maxLine * spacing);
  114.         }
  115.  
  116.         /****     Set foreground color    ****/
  117.         fontColor = new Color(fRed, fGreen, fBlue);
  118.  
  119.         /****     Set background color    ****/
  120.         background = new Color(Red, Green, Blue);
  121.         setBackground(background);
  122.  
  123.  
  124.         /****         Init buffer         ****/
  125.         offImage = createImage(size().width, size().height);
  126.         offGrfx = offImage.getGraphics();
  127.  
  128.     }
  129.  
  130.     public void paint(Graphics screen) {
  131.  
  132.         /****     Clear prev image        ****/
  133.           offGrfx.setColor(background);
  134.           offGrfx.fillRect(0,0,size().width, size().height);
  135.  
  136.         /****      Draw background        ****/
  137.           if (bg != null)
  138.             offGrfx.drawImage(bg, 0, current - height, null);
  139.  
  140.         /****      Set custom font        ****/
  141.           offGrfx.setColor(fontColor);
  142.           try { offGrfx.setFont(outFont); }
  143.           catch (NullPointerException e) {}
  144.  
  145.         /****        Draw lines           ****/
  146.           if (direction == 0) {
  147.               for (int i=0; i<maxLine; i++) 
  148.                   offGrfx.drawString(Line[i],  XPos, current + (i * spacing));
  149.           }
  150.           else {
  151.               for (int i=0; i<maxLine; i++)
  152.                   offGrfx.drawString(Line[i],  XPos, current + ( (maxLine-i) * spacing));
  153.           }
  154.  
  155.         /****   Flip buffer to screen     ****/
  156.           screen.drawImage(offImage, 0, 0, this);
  157.     }
  158.  
  159.     public void update(Graphics screen) {
  160.  
  161.         /****      Override update        ****/
  162.           paint(screen);
  163.     }
  164.  
  165.     public void start() {
  166.         if (runner == null) {
  167.             runner = new Thread(this);
  168.             runner.start();
  169.         }
  170.     }
  171.  
  172.     public void run() {
  173.         while (true) {
  174.             repaint();
  175.             if (direction == 0) {
  176.                 current--;
  177.                 if ((current + (maxLine * spacing)) < 0)
  178.                 current = height + spacing;
  179.             }
  180.             else {
  181.                 current++;
  182.                 if (current > height)
  183.                 current = -(maxLine * spacing);
  184.             }
  185.             try { Thread.sleep(delay); }
  186.             catch (InterruptedException e) { }
  187.         }
  188.     }
  189.  
  190.     public void stop() {
  191.         if (runner != null) {
  192.             runner.stop();
  193.             runner = null;
  194.         }
  195.     }
  196. }
  197.